package com.pokermind.model.po;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 扑克AI决策快照实体类
 * 对应 poker_decision_snapshots 表
 * 
 * @author PokerMind Team
 */
public class PokerDecisionSnapshot {
    
    /** 主键ID */
    private Long id;
    
    /** 用户ID */
    private Long userId;
    
    /** 手牌ID */
    private Long handId;
    
    /** 快照序号 */
    private Integer snapshotSequence;
    
    /** 完整游戏状态JSON */
    private String gameState;
    
    /** AI推荐行动 */
    private String aiRecommendation;
    
    /** AI置信度 */
    private BigDecimal aiConfidence;
    
    /** AI推理过程 */
    private String aiReasoning;
    
    /** 创建时间 */
    private LocalDateTime createdAt;
    
    // AI推荐行动常量
    public static final String RECOMMENDATION_FOLD = "fold";
    public static final String RECOMMENDATION_CHECK = "check";
    public static final String RECOMMENDATION_CALL = "call";
    public static final String RECOMMENDATION_BET = "bet";
    public static final String RECOMMENDATION_RAISE = "raise";
    public static final String RECOMMENDATION_ALLIN = "allin";
    
    // 默认构造函数
    public PokerDecisionSnapshot() {
        this.createdAt = LocalDateTime.now();
    }
    
    // 业务构造函数
    public PokerDecisionSnapshot(Long userId, Long handId, Integer snapshotSequence, String gameState) {
        this();
        this.userId = userId;
        this.handId = handId;
        this.snapshotSequence = snapshotSequence;
        this.gameState = gameState;
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public Long getHandId() {
        return handId;
    }
    
    public void setHandId(Long handId) {
        this.handId = handId;
    }
    
    public Integer getSnapshotSequence() {
        return snapshotSequence;
    }
    
    public void setSnapshotSequence(Integer snapshotSequence) {
        this.snapshotSequence = snapshotSequence;
    }
    
    public String getGameState() {
        return gameState;
    }
    
    public void setGameState(String gameState) {
        this.gameState = gameState;
    }
    
    public String getAiRecommendation() {
        return aiRecommendation;
    }
    
    public void setAiRecommendation(String aiRecommendation) {
        this.aiRecommendation = aiRecommendation;
    }
    
    public BigDecimal getAiConfidence() {
        return aiConfidence;
    }
    
    public void setAiConfidence(BigDecimal aiConfidence) {
        this.aiConfidence = aiConfidence;
    }
    
    public String getAiReasoning() {
        return aiReasoning;
    }
    
    public void setAiReasoning(String aiReasoning) {
        this.aiReasoning = aiReasoning;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    // 业务方法
    /**
     * 设置AI分析结果
     */
    public void setAiAnalysis(String recommendation, BigDecimal confidence, String reasoning) {
        this.aiRecommendation = recommendation;
        this.aiConfidence = confidence;
        this.aiReasoning = reasoning;
    }
    
    /**
     * 检查是否有AI分析结果
     */
    public boolean hasAiAnalysis() {
        return aiRecommendation != null && !aiRecommendation.trim().isEmpty();
    }
    
    /**
     * 获取置信度百分比
     */
    public Integer getConfidencePercentage() {
        if (aiConfidence == null) return null;
        return aiConfidence.multiply(BigDecimal.valueOf(100)).intValue();
    }
    
    /**
     * 检查是否为高置信度推荐
     */
    public boolean isHighConfidence() {
        return aiConfidence != null && aiConfidence.compareTo(BigDecimal.valueOf(0.8)) >= 0;
    }
    
    /**
     * 检查是否为主动推荐
     */
    public boolean isAggressiveRecommendation() {
        return RECOMMENDATION_BET.equals(aiRecommendation) || 
               RECOMMENDATION_RAISE.equals(aiRecommendation) || 
               RECOMMENDATION_ALLIN.equals(aiRecommendation);
    }
    
    /**
     * 检查是否为保守推荐
     */
    public boolean isConservativeRecommendation() {
        return RECOMMENDATION_FOLD.equals(aiRecommendation) || 
               RECOMMENDATION_CHECK.equals(aiRecommendation) || 
               RECOMMENDATION_CALL.equals(aiRecommendation);
    }
    
    @Override
    public String toString() {
        return "PokerDecisionSnapshot{" +
                "id=" + id +
                ", userId=" + userId +
                ", handId=" + handId +
                ", snapshotSequence=" + snapshotSequence +
                ", aiRecommendation='" + aiRecommendation + '\'' +
                ", aiConfidence=" + aiConfidence +
                ", createdAt=" + createdAt +
                '}';
    }
}